
#! ruby
require 'fileutils'

task :woof => [] do
  Dir.chdir("vm"){
#    system "mzc -k kernel.scm"
#    system "mzc -k machine-utils.scm"
#    system "mzc -k instructions.scm"
#    system "mzc -k primitives.scm"
#    system "mzc -k machine.scm"
#    system "mzc -k compiler.scm"
#    system "mzc -k main.scm"
    system "mzc --exe woof.exe main.scm"
    FileUtils.mv "woof.exe", "../"
  }
end

task :woofc => [] do
  Dir.chdir("compiler"){
    system "alex woof_lex.x"
    system "ghc --make -package parsec -package mtl woof_lex.hs woof_parse.hs woof_main.hs woof_to_bc.hs -o woofc"
    FileUtils.mv "woofc.exe", "../"
  }
end

task :wooft => [] do
  Dir.chdir("compiler"){
    system "alex woof_lex.x"
    system "ghc --make -package parsec -package mtl woof_lex.hs woof_parse.hs woof_main_tree.hs woof_to_dot.hs -o wooft"
    FileUtils.mv "wooft.exe", "../"
  }
end

task :test_vm => [:woofc] do
  Dir.chdir("vm"){
    system "mzscheme -t all-tests.scm"
  }
end

task :test_woof => [:woof, :woofc] do
  system "woof.exe test_all.woof"
end

task :test_all => [:test_vm, :test_woof] do
end

# Visualize the program structure
# Usage: rake gen_tree input.woof
task :gen_tree => [:wooft] do
  system "wooft.exe < #{ARGV[1]} | dot -Tsvg -o #{File.basename(ARGV[1])}.svg"
end






